<?php

function list_sk(){
	my_set_code_js('
		function confirmDelete( i){
		var check = confirm(\'Akan mendelete data? \'); 
		if(check){
			location.href=\'index.php?com='.$_GET['com'].'&task=delete&id=\'+i;
		}
		return;	}
	');
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'Nomor SK'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Tanggal SK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:15%'),  
		'Status Pemberhentian'=>array('style'=>'text-align:center;border-bottom:2px solid;width:50'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	if(isset($_GET['key'])){
	$query = "
		SELECT * FROM sk_pemberhentian a 
		WHERE a.nomor LIKE '%{$_GET['key']}%' OR a.status_henti ='{$_GET['key']}'
	"; 
	}else{
	$query = "SELECT * FROM sk_pemberhentian ORDER BY sk_id DESC";
	}
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =7;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		  
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	
	$kgPagerOBJ = new kgPager();
			$kgPagerOBJ->pager_set(
				$pager_url, 
				$total_records, 
				$scroll_page, 
				$per_page, 
				$current_page, 
				$inactive_page_tag, 
				$previous_page_text, 
				$next_page_text, 
				$first_page_text, 
				$last_page_text ,$pager_url_last); 
				
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
			'href'=>'index.php?com=pemberhentian&task=edit&id='.$ey['sk_id'],
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );
		$detailproperty = array(
			'href'=>'index.php?com=pemberhentian&task=detail&sk_id='.$ey['sk_id'],
			'title'=>'Detail'
		);
		$detail_button = button_icon( 'b_props.png' , $detailproperty  );

		$deleteproperty = array(
			'href'=>'javascript:; ',
			'onclick'=>'javascript:confirmDelete('.$ey['sk_id'].');',
			'title'=>'Delete'
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'nomor'=>  strtoupper($ey['nomor'] ),   
			'tgl'=>  position_text_align( date( "d-m-Y" , strtotime($ey['tanggal_surat'].' 00:00:00')) ,   'center' ),
			'status'=>  position_text_align( $ey['status_henti']  , 'center') , 
			'operasi'=> position_text_align(  $edit_button.' '. $delete_button.' '. $detail_button , 'right'),  
		); 
	}
	
	$datas = table_rows($row); 
	if(is_admin()):
		$menuontop = array(  
			'Tambah data'=>array('onclick'=>'javascript:location.href=\'index.php?com=pemberhentian&task=edit&id=0\';')
			//'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com=report&task=pemberhentian\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,resizable=0\');')
		);
	else:
	endif;	
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" /><span style="font:10px verdana"><b>Pencarian cepat</b></span><br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" /><input class="simple_search" type="submit" value=" CARI " /> </form>';
	 
	$printmenu = additional_menu_on_list( $menuontop ,$search );
	
	$paging = $kgPagerOBJ ->showPaging();	
	return $printmenu .table_builder($header , $datas ,  5 , false ,$paging  );
} 



function form_sk( $id ){
	my_set_file_js(
		array(
			'components/system/jquery/combomulti/jquery.chainedSelects.js',
			'components/system/js/calendar/calendarDateInput.js' 
		)
	);
		
	$view = form_header( "seleski" , "seleski"  );
 	$fields = my_get_data_by_id('sk_pemberhentian','sk_id',$id);

	$nomor = array(
			'name'=>'nomor',
			'value'=>(isset($_POST['nomor'])? $_POST['nomor'] : $fields['nomor']),
			'id'=>'nomor',
			'type'=>'textfield',
			'size'=>'15'
		);
	$form_nomor = form_dynamic($nomor);
	$view .= form_field_display( $form_nomor  , "Nomor SK"  );

	$ftanggalm = $ftanggal = date('d-m-Y');
	if($fields){
		list($yyyytanggal , $mmtanggal,$ddtanggal ) = explode("-" ,$fields['tanggal_surat'] );
		list($yyyytanggalm , $mmtanggalm,$ddtanggalm ) = explode("-" ,$fields['tmt'] );
		$ftanggal = $ddtanggal.'-'.$mmtanggal.'-'.$yyyytanggal;
		$ftanggalm = $ddtanggalm.'-'.$mmtanggalm.'-'.$yyyytanggalm;
	}
	
	$tanggal = array(
		'name'=>'tanggal_surat',
		'value'=>(isset($_POST['tanggal_surat'])? $_POST['tanggal_surat'] : $ftanggal),
		'id'=>'tanggal',
		'type'=>'textfield',
		'size'=>'45'
	);
	$form_tanggal = form_calendar($tanggal);
	$view .= form_field_display( $form_tanggal  , "Tanggal SK" );
 
	$status_hentis = array(
		 'Pensiun'=>'Pensiun', 
		 'Mengundurkan diri'=> 'Mengundurkan diri', 
		 'Diberhentikan'=>'Diberhentikan', 
		 'Meninggal dunia'=>'Meninggal dunia', 
		 'Habis masa kontrak'=>'Habis masa kontrak',
		 'Lainnya'=>'Lainnya'
	);
	$status_henti = array(
		'name'=>'status_henti',
		'value'=>(isset($_POST['status_henti']) ? $_POST['status_henti'] : $fields['status_henti']),
		'id'=>'status_henti' 
	);
	$form_status_henti = form_dropdown( $status_henti , $status_hentis );
	$view .= form_field_display( $form_status_henti , "Status pemberhentian" );
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	
	$back = array(
		'value' => '  Kembali  ' ,
		'name' => 'back', 'onclick'=>'location.href=\'index.php?com=pemberhentian\'',
		'type'=>'button','class'=>'main_button'
	);
	$form_back= form_dynamic($back); 
	
	$view .= form_field_display( $form_submit .' '. $form_back  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}

function submit_sk($id = 0){

	if($_POST){
		list( $ddtanggal, $mmtanggal,$yyyytanggal ) = explode("-" ,$_POST['tanggal_surat'] );
		$ftanggal = $yyyytanggal.'-'.$mmtanggal.'-'.$ddtanggal;
	}
	$datas = array(
		'nomor'=>my_type_data_str($_POST['nomor']),
		'tanggal_surat'=>my_type_data_str($ftanggal),
		'status_henti'=>my_type_data_str($_POST['status_henti']),
		'datetime_added'=>my_type_data_function('NOW()'),
	);
	 
	if($id > 0){
		return my_update_record('sk_pemberhentian','sk_id',$id,$datas);
	}
	$new_id = my_insert_record('sk_pemberhentian',$datas);
	return $new_id;
}

function delete_sk($id){
	return my_delete_record('sk_pemberhentian','sk_id',$id);
}


function list_karyawan($sk_id){
	my_set_code_js('
		function confirmDelete( i){
		var check = confirm(\'Akan mendelete data? \'); 
		if(check){
			location.href=\'index.php?com='.$_GET['com'].'&task=delete_karyawan&sk_id='.$sk_id.'&id=\'+i;
		}
		return;	}
	');
	$header = array(
		'#'=>array('style'=>'text-align:center;border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Karyawan'=>array('style'=>'border-bottom:2px solid;width:35%'),  
		'Tanggal Efektif'=>array('style'=>'text-align:center;border-bottom:2px solid;width:15%'),  
		'Pensiun/Pesangon'=>array('style'=>'text-align:right;border-bottom:2px solid;width:25%'),  
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	if(isset($_GET['key'])){
		$query = "
			SELECT * FROM pemberhentian c 
			INNER JOIN karyawan a ON a.karyawan_id = c.karyawan_id
			INNER JOIN biodata b 
			ON a.biodata_id = b.biodata_id
			WHERE c.sk_id={$sk_id} and (b.nama LIKE '%{$_GET['key']}%' OR a.nik ='{$_GET['key']})'
		"; 
	}else{
		$query = "SELECT * FROM pemberhentian a INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id WHERE sk_id={$sk_id}";
	}
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =7;  
	$per_page =25;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		  
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&sk_id={$_GET['sk_id']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	
	$kgPagerOBJ = new kgPager();
			$kgPagerOBJ->pager_set(
				$pager_url, 
				$total_records, 
				$scroll_page, 
				$per_page, 
				$current_page, 
				$inactive_page_tag, 
				$previous_page_text, 
				$next_page_text, 
				$first_page_text, 
				$last_page_text ,$pager_url_last); 
				
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 25; 
	while($ey = my_fetch_array($result)){
		$i++;
		$editproperty = array(
			'href'=>'index.php?com=pemberhentian&task=edit_karyawan&sk_id='.$sk_id.'&id='.$ey['pemberhentian_id'],
			'title'=>'Edit'
		);
		$edit_button = button_icon( 'b_edit.png' , $editproperty  );

		$deleteproperty = array(
			'href'=>'javascript:; ',
			'onclick'=>'javascript:confirmDelete('.$ey['pemberhentian_id'].');',
			'title'=>'Delete'
		);
		$delete_button = button_icon( 'b_drop.png' , $deleteproperty  );
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'nik'=>  position_text_align( $ey['nik']  , 'center') , 
			'nama'=> $karyawan['nama_gelar'] ,
			'tmt'=>  position_text_align( date( "d-m-Y" , strtotime($ey['tmt'].' 00:00:00')) ,   'center' ),
			'nominal'=> position_text_align( rp_format($ey['nominal']),'right') ,
			'operasi'=> position_text_align(  $edit_button.' '. $delete_button , 'right'),  
		); 
	}
	$sks = my_get_data_by_id('sk_pemberhentian','sk_id',$sk_id );
	$view  = form_header( "..." , "..."  );
	$view .=form_field_display( '<span class="label_form">'. $sks['nomor'] .'</span>'   , "<b>Nomor Surat</b>"    ) ;
	$view .=form_field_display( '<span class="label_form">'.  date( "d-m-Y" , strtotime($sks['tanggal_surat'])) .'</span>'   , "<b>Tanggal Surat</b>"    ) ;
	$view .=form_field_display( '<span class="label_form">'.  $sks['status_henti'].'</span>'   , "<b>Status Pemberhentian</b>"    ) ;
	$view  .= form_footer(  );
	//if($sks['status_henti']=="Pensiun"){
	//	$menuontop = array(  
	//		'Tambah data'=>array('onclick'=>'javascript:location.href=\'index.php?com=pemberhentian&task=list_mpp&sk_id='.$sk_id.'\';'),
	//		'Kembali' => array('onclick'=>'javascript:location.href=\'index.php?com=pemberhentian'.'\''), 
	//	);	
	//}else{
		$menuontop = array(  
			'Tambah data'=>array('onclick'=>'javascript:location.href=\'index.php?com=pemberhentian&task=edit_karyawan&sk_id='.$sk_id.'&id=0\';'),
			'Kembali' => array('onclick'=>'javascript:location.href=\'index.php?com=pemberhentian'.'\''), 
		);	
	//}
	$printmenu = additional_menu_on_list( $menuontop ,'' ); 
	$datas = table_rows($row); 
	
	$paging = $kgPagerOBJ ->showPaging();	
	return $view.$printmenu.table_builder($header , $datas , 6, false ,$paging);
} 

 
function form_edit_karyawan( $sk_id ,$id ){
	my_set_file_js(
		array(
			'components/system/jquery/combomulti/jquery.chainedSelects.js',
			'components/system/js/calendar/calendarDateInput.js' 
		)
	);
		
	my_set_file_js(
		array(
			'components/system/jquery/autocomplete/jquery.autocomplete.js'  
		)
	);
	my_set_file_css(
	array(
			'components/system/jquery/autocomplete/jquery.autocomplete.css' 
		)
	);

	my_set_code_js('  
		function findValue(li) {
			if( li == null ) return alert("No match!"); 
			if( !!li.extra ) var sValue = li.extra[0]; 
			else var sValue = li.selectValue;
		}

		function selectItem(li) {
			findValue(li);
		}

		function formatItem(row) {
			return   row[0] ;
		}

		function lookupAjax(){
			var oSuggest = $("#nama_karyawan")[0].autocompleter;
			oSuggest.findValue(); 
			return false;
		}
		$(document).ready(function() {
			$("#nama_karyawan").autocomplete(
				"autocomplete_daftar_karyawan.php",
				{
					delay:10,
					minChars:2,
					matchSubset:1,
					matchContains:1,
					cacheLength:5,
					onItemSelect:selectItem,
					onFindValue:findValue,
					formatItem:formatItem,
					autoFill:true
				}
			);
			 
		});

		function checkName(name){
			$.get("check_karyawan_names.php", { nama: name  },
			   function(data){
				 if(data ==  \'0\' ){
					alert(\'Nama karyawan \'+ name+\' tidak ditemukan\nHarap diperiksa kembali\');
					$(\'#nama_karyawan\').val(\'\');
					return false;
				 } 
			   });
		}
	');

	$view = form_header( "seleski" , "seleski"  );
 	$fields = my_get_data_by_id('pemberhentian','pemberhentian_id',$id);


	$ftanggalm = $ftanggal = date('d-m-Y');
	if($fields){
		list($yyyytanggalm , $mmtanggalm,$ddtanggalm ) = explode("-" ,$fields['tmt'] );
		$ftanggalm = $ddtanggalm.'-'.$mmtanggalm.'-'.$yyyytanggalm;
	}
	$tanggal_mulai = array(
		'name'=>'tanggal_mulai',
		'value'=>(isset($_POST['tanggal_mulai'])? $_POST['tanggal_mulai'] : $ftanggalm),
		'id'=>'tanggal_mulai' 
	);
	$form_tanggal_mulai = form_calendar($tanggal_mulai);
	$view .= form_field_display( $form_tanggal_mulai , "Tanggal Efektif" );
	
	$karyawan_data = loaddata_karyawan(( $fields ? $fields['karyawan_id'] : 0));
	$karyawan = array(
		'name'=>'nama_karyawan',
		'value'=>(isset($_POST['nama_karyawan'])? $_POST['nama_karyawan'] : $karyawan_data['nik']. (isset($karyawan_data) ? '/' : '').$karyawan_data['nama']  ),
		'id'=>'nama_karyawan',
		'type'=>'textfield',
		'size'=>'35'
	);
	$form_karyawan = form_dynamic($karyawan);
	$view .= form_field_display( $form_karyawan  , "NIK/Nama Karyawan"  );

	$nominal = array(
				'name'=>'nominal',
				'value'=>( isset($_POST['nominal']) ? $_POST['nominal'] : rp_format($fields['nominal']))  ,
				'id'=>'nominal',
				'type'=>'text',
				'size'=>'20'
			);
	$form_nominal = form_money($nominal);
	$view .= form_field_display( $form_nominal  , "<span id=\"pesangon\">Pensiun/Pesangon diterima</span>"  );
	
	
	$catatan = array(
			'name'=>'catatan',
			'value'=>(isset($_POST['catatan'])? $_POST['catatan'] : $fields['catatan']),
			'id'=>'catatan', 
		);
	$form_catatan = form_textarea($catatan);
	$view .= form_field_display( $form_catatan  , " Catatan"  );
	
	$submit = array(
		'value' => ( $id ==0 ? ' Simpan ' :'  Update  '),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 
	
	
	$back = array(
		'value' => '  Kembali  ' ,
		'name' => 'back', 'onclick'=>'location.href=\'index.php?com=pemberhentian&task=detail&sk_id='.$sk_id.'\'',
		'type'=>'button','class'=>'main_button'
	);
	$form_back= form_dynamic($back); 
	
	$view .= form_field_display( $form_submit .' '. $form_back  , "&nbsp;" ,  "" );
	$view .= form_footer( );
	return $view;
}

function submit_karyawan($sk_id,$id = 0){

	$karyawan_id = check_karyawan_by_nik_nama($_POST['nama_karyawan']);
	if($_POST){
		list($ddtanggalm , $mmtanggalm, $yyyytanggalm) = explode("-" ,$_POST['tanggal_mulai'] );
		$ftanggalm = $yyyytanggalm.'-'.$mmtanggalm.'-'.$ddtanggalm;
	}
	$datas = array(
		'sk_id'=>my_type_data_int($sk_id),
		'karyawan_id'=>my_type_data_int($karyawan_id),
		'tmt'=>my_type_data_str($ftanggalm),
		'catatan'=>my_type_data_str($_POST['catatan']),
		'nominal'=>my_type_data_str(set_text_as_number($_POST['nominal'])),
	);
	 
	if($id > 0){
		return my_update_record('pemberhentian','pemberhentian_id',$id,$datas);
	}
	$new_id = my_insert_record('pemberhentian',$datas);
	return $new_id;
}

function delete_karyawan($sk_id,$id){
	return my_delete_record('pemberhentian','pemberhentian_id',$id);
}


function list_mpp($sk_id){

my_set_file_js(
	array(
		'components/system/jquery/combomulti/jquery.chainedSelects.js',
		'components/system/js/calendar/calendarDateInput.js' 
	)
);
	$tgl = date("Y-m-d");
	$ftanggal = date('d').'-'.date('m').'-'.(date('Y')-1);
	if($_GET['tanggal']){ 
		list($ddtanggal , $mmtanggal , $yyyytanggal  ) = explode("-" ,$_GET['tanggal'] );
		$tgl = $yyyytanggal ."-". $mmtanggal."-".$ddtanggal;
		$ftanggal = $_GET['tanggal'];
	}
	$tanggal = array(
			'name'=>'tanggal',
			'id'=>'tanggal',
			'value'=>$ftanggal,
		);
		
	$tgl2 = date("Y-m-d");
	$ftanggal2 = date('d-m-Y');
	if($_GET['tanggal']){ 
		list($ddtanggal2 , $mmtanggal2 , $yyyytanggal2  ) = explode("-" ,$_GET['tanggal2'] );
		$tgl2 = $yyyytanggal2 ."-". $mmtanggal2."-".$ddtangga2;
		$ftanggal2 = $_GET['tanggal2'];
	}
	$tanggal2 = array(
			'name'=>'tanggal2',
			'id'=>'tanggal2',
			'value'=>$ftanggal2,
		);
	if(isset($_GET['tanggal']) && isset($_GET['tanggal2'])){
		list($dd1,$mm1,$yyyy1) = explode("-" , $_GET['tanggal']);
		list($dd2,$mm2,$yyyy2) = explode("-" , $_GET['tanggal2']);
		$startDate = $yyyy1.'-'.$mm1.'-'.$dd1; 
		$endDate = $yyyy2.'-'.$mm2.'-'.$dd2;
	}else{
		$startDate =   date("Y")-1 . '-'. date("m-d");
		$endDate =  date("Y-m-d");
	}
	
	
	$_GET['nik_start'] = isset($_GET['nik_start']) ? sprintf('%07d',(int)$_GET['nik_start']) :'0000001'; 	
	$_GET['nik_end'] = isset($_GET['nik_end']) ? sprintf('%07d',(int)$_GET['nik_end']) :'9999999'; 	
	$nik_start = isset($_GET['nik_start']) ? $_GET['nik_start'] : $nik_start_default;
	$nik_end = isset($_GET['nik_end']) ? $_GET['nik_end'] : $nik_end_default;
	
	$view ="<form method=\"GET\">
	<input type=\"hidden\" name=\"com\" value=\"{$_GET['com']}\" />
	<table border=\"0\" width=\"100%\"> <tr><td width='15%'>Prediksi pensiun   :</td>
	<td width='20%'>".form_calendar($tanggal)." </td>
	<td width='3%'>s/d</td><td width='20%'> ".form_calendar($tanggal2)."</td>
	<td width=\"10%\"> <input type=\"submit\" value=\"GO\" class=\"simple_search\"/></td>
	<td align=\"right\" width=\"51%\">  
	
	</td></tr></table></form>";
	
	
	$header = array(
		' '=>array('style'=>'border-bottom:2px solid;width:5%'),
		'Prediksi Pensiun'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'NIK'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Nama karyawan'=>array('style'=>'text-align:center;border-bottom:2px solid;width:30%'),  
		'Jabatan'=>array('style'=>'text-align:center;border-bottom:2px solid;width:30%'),  
		'Tgl. Lahir'=>array('style'=>'border-bottom:2px solid;width:15%'),  
	);
	$query = "SELECT a.karyawan_id,
		DATE_ADD(b.tanggal_lahir,INTERVAL 56 YEAR) as period,
		b.tanggal_lahir FROM `karyawan`a
		INNER JOIN biodata b ON a.biodata_id=b.biodata_id 
		WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
		 
		AND   ( 
		 '{$endDate}' >=  	DATE_ADD(b.tanggal_lahir, INTERVAL 56 YEAR)
			AND
		 '{$startDate}' <=  DATE_ADD(b.tanggal_lahir, INTERVAL 56 YEAR)
		)
		
		AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 
		ORDER BY YEAR(period),MONTH(period)";
	 
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =35;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&field={$_GET['field']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
			$kgPagerOBJ->pager_set(
				$pager_url, 
				$total_records, 
				$scroll_page, 
				$per_page, 
				$current_page, 
				$inactive_page_tag, 
				$previous_page_text, 
				$next_page_text, 
				$first_page_text, 
				$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 35; 
	while( $ey = my_fetch_array($result) ){
		$i++;
		$karyawan = loaddata_karyawan($ey['karyawan_id']);
		$jab = loaddata_jabatan($karyawan['jabatan_id']);		
			$prediksi = get_prediksi($ey['tanggal_lahir']);
		$fr = '<input type="checkbox" name="a['.$ey['karyawan_id'].']" value="1" '.( pensiun_cek($sk_id,$ey['karyawan_id']) ? ' checked="checked" ': '').'/>';		

		$row[] = array(
			'a'=>position_text_align( $fr,'center'),
			'prediksi'=>position_text_align(  date('d-m-Y',strtotime($ey['period'])) , 'center') ,	
			'nik'=>  position_text_align(    $karyawan['nik'] ,   'center' ),
			'nama'=> $karyawan['nama_gelar']   , 
			'jbt'=>  $jab['nama_jabatan']   , 
			'tmb'=>  position_text_align( date( "d-m-Y" , strtotime($ey['tanggal_lahir'] )) , 'center') , 
		
		);
	}
	$datas = table_rows($row); 
	$menuontop = array(
		'Kembali' => array('onclick'=>'javascript:location.href=\'index.php?com=pemberhentian&task=detail&sk_id='.$sk_id.'\''), 
		'Simpan' => array('onclick'=>'javascript:document.formDataSubmit.submit()')
	);
	$printmenu = additional_menu_on_list( $menuontop ,'');
	return  $view . $printmenu.'<form method="POST" name="formDataSubmit">'.table_builder($header , $datas ,  5 , false ).'</form>';
}

function get_prediksi($tanggal){
 
	list($ymd , $ht) = explode(" " , $tanggal);
	list($yyyy,$mm,$dd) =explode("-" , $ymd); 
	$tyear = $dd .'-'.$mm.'-'. $yyyy;
	if((int) $yyyy > 0)
	$tyear =$dd .'-'.$mm.'-'.( $yyyy+56 );
	return $tyear;
}


function stor_karyawan_pensiun($sk_id){

	foreach($_POST['a'] as $k=>$iv){
		$query = "SELECT * FROM pemberhentian WHERE sk_id = {$sk_id} 
		AND karyawan_id = {$k}";
		$result = my_query($query);
		$pensiuns = my_fetch_array($result);
		$id=0;
		if(my_num_rows($result) > 0){
			$id=$pensiuns['pemberhentian_id'];
		}
		
		$datas = array(
			'sk_id'=>my_type_data_int($sk_id),
			'karyawan_id'=>my_type_data_int($k),
		);	 
		if($id>0){
			my_update_record('pemberhentian','pemberhentian_id',$id,$datas);
		}else{
			my_insert_record('pemberhentian',$datas);
		}
	}
}

function pensiun_cek($sk_id,$karyawan_id){
	$query = "SELECT * FROM pemberhentian WHERE sk_id = {$sk_id} 
		AND karyawan_id = {$karyawan_id}";
	$result = my_query($query);
	if(my_num_rows($result) == 0){
		return false;
	}
	return true;
}